package ordinaryThree;

import sun.security.util.Length;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Wukong
 * Date: 2022-06-01
 * Time: 21:09
 */

/**
 * 自定义异常通常会继承自 Exception 或者 RuntimeException
 * 继承自 Exception 的异常默认是受查异常
 * 继承自 RuntimeException 的异常默认是非受查异常
 */
public class Exception {
    public static void main(String[] args) {
        try {
            Login("wukong","123456");
        }
        catch (UserWord userWord){
            userWord.printStackTrace();
        }
        catch (UserName userWord){
            userWord.printStackTrace();
        }

    }
   static void Login(String name, String word) throws UserName, UserWord {
        if (!name.equals(name)){
            throw new UserName("用户名错误");
        }
        if (!word.equals(word)){
            throw new UserWord("密码错误");
        }
        System.out.println("登录成功！");
    }



}
